using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;

using GonzalesCore.CoreElements;
using GonzalesCore.CoreManagers;
using Kypris2.CoreElements;
using Kypris2.Utils;
using Jamila2.Tools;

public partial class GonzalesAdminFAListing : System.Web.UI.Page
{
    #region Variables

    protected PrivateLoginSession CurrentPrivateSession = null;
    protected LogManager CurLogManager = null;
    protected DataObj CurPageDataObj = new DataObj();

    #region ResultTable
    protected DataTable ResultTable
    {
        get
        {
            return (DataTable)ViewState["ResultTable"];
        }

        set
        {
            ViewState["ResultTable"] = value;
        }
    }
    #endregion

    #region GridViewHeader
    protected ArrayList GridViewHeader
    {
        get
        {
            return (ArrayList)ViewState["GridViewHeader"];
        }

        set
        {
            ViewState["GridViewHeader"] = value;
        }
    }
    #endregion

    #region SavedSucessfulMessage
    protected string SavedSucessfulMessage
    {
        get
        {
            return ViewState["SavedSucessfulMessage"].ToString();
        }

        set
        {
            ViewState["SavedSucessfulMessage"] = value;
        }
    }
    #endregion

    #region SavedFailedMessagee
    protected string SavedFailedMessagee
    {
        get
        {
            return ViewState["SavedFailedMessagee"].ToString();
        }

        set
        {
            ViewState["SavedFailedMessagee"] = value;
        }
    }
    #endregion

    #region LoadFailedMessage
    protected string LoadFailedMessage
    {
        get
        {
            return ViewState["LoadFailedMessage"].ToString();
        }

        set
        {
            ViewState["LoadFailedMessage"] = value;
        }
    }
    #endregion

    #region CompanyMessage
    protected string CompanyMessage
    {
        get
        {
            return ViewState["CompanyMessage"].ToString();
        }

        set
        {
            ViewState["CompanyMessage"] = value;
        }
    }
    #endregion

    #region FinanceAdminMessage
    protected string FinanceAdminMessage
    {
        get
        {
            return ViewState["FinanceAdminMessage"].ToString();
        }

        set
        {
            ViewState["FinanceAdminMessage"] = value;
        }
    }
    #endregion

    #region DuplicateFAMessage
    protected string DuplicateFAMessage
    {
        get
        {
            return ViewState["DuplicateFAMessage"].ToString();
        }

        set
        {
            ViewState["DuplicateFAMessage"] = value;
        }
    }
    #endregion

    #region DeletionFailedMessage
    protected string DeletionFailedMessage
    {
        get
        {
            return ViewState["DeletionFailedMessage"].ToString();
        }

        set
        {
            ViewState["DeletionFailedMessage"] = value;
        }
    }
    #endregion

    #endregion

    #region Events

    #region Page_Load
    protected void Page_Load(object sender, EventArgs e)
    {
        this.SessionCheck();

        this.Table_MessageBox.Visible = false;

        if (!IsPostBack)
        {
            if (this.CurrentPrivateSession.CurrentLoggedOnUser.IsFinanceAdmin)
            {
                if (!this.CurrentPrivateSession.CurrentLoggedOnUser.IsFinancialManager)
                {
                    Button_Submit.Visible = false;
                }
                else
                {
                    CheckBox_IsFinancialManager.Checked = 
                    CheckBox_IsFinancialManager.Enabled = false;
                }
            }
            else if (this.CurrentPrivateSession.CurrentLoggedOnUser.IsITAdmin)
            {
                Button_Submit.Visible = false;
            }
            else if (this.CurrentPrivateSession.CurrentLoggedOnUser.IsPowerAdmin)
            {
                CheckBox_IsFinancialManager.Checked = true;
                CheckBox_IsFinancialManager.Enabled = false;
            }

            this.SwitchLanguage();
            this.PageComponentSetup();

            // check if any delete
            this.DataDelete();

            this.LoadData();

            if (this.ResultTable != null)
            {
                DataView ResultView = new DataView(this.ResultTable);
                ResultView.Sort = this.DropDownList_SortBy.SelectedValue + " " + this.DropDownList_SortOrder.SelectedValue;
                this.BindData(ResultView);
            }
        }
    }
    #endregion

    #region DropDownList_ByEntity_SelectedIndexChanged
    protected void DropDownList_ByEntity_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (this.DropDownList_ByEntity.SelectedValue.Length > 0)
        {
            using (CompanyManager CurCompanyManager = new CompanyManager(this.CurrentPrivateSession))
            {
                GonzalesCompanies ResultList = CurCompanyManager.GetCompanyByEntityID(this.DropDownList_ByEntity.SelectedValue);

                if (ResultList != null)
                {
                    this.DropDownList_ByCompany.Items.Clear();
                    this.DropDownList_ByCompany.Items.Add(new ListItem("", ""));

                    for (int x = 0; x < ResultList.Count; x++)
                    {
                        this.DropDownList_ByCompany.Items.Add(new ListItem(ResultList[x].CompanyName, ResultList[x].InternalID));
                    }
                }
                else
                {
                    this.CurLogManager.LogError("[GonzalesAdminFIListing.DropDownList_ByEntity_SelectedIndexChanged] : Failed on CurCompanyManager.GetCompanyByEntityID('" + this.DropDownList_ByEntity.SelectedValue + "') : " + CurCompanyManager.ErrorMessage, this.CurrentPrivateSession.CurrentLoggedOnUser, LogInterface.System);
                }
            }
        }
    }
    #endregion

    #region DropDownList_ByCompany_SelectedIndexChanged
    protected void DropDownList_ByCompany_SelectedIndexChanged(object sender, EventArgs e)
    {
        this.LabelValue_Company.Text = this.DropDownList_ByCompany.SelectedItem.Text;

        this.LoadData();

        if (this.ResultTable != null)
        {
            DataView ResultView = new DataView(this.ResultTable);
            ResultView.Sort = this.DropDownList_SortBy.SelectedValue + " " + this.DropDownList_SortOrder.SelectedValue;
            this.BindData(ResultView);            
        }

        // log down the history
        this.CurLogManager.LogMessage("[GonzalesAdminFAListing] : Finance Verifier for Company(" + this.DropDownList_ByCompany.SelectedValue + ", " + this.DropDownList_ByCompany.SelectedItem.Text + ") viewed", this.CurrentPrivateSession.CurrentLoggedOnUser, LogInterface.User);

    }
    #endregion

    #region DropDownList_SortBy_SelectedIndexChanged
    protected void DropDownList_SortBy_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (this.ResultTable != null)
        {
            DataView ResultView = new DataView(this.ResultTable);
            ResultView.Sort = this.DropDownList_SortBy.SelectedValue + " " + this.DropDownList_SortOrder.SelectedValue;
            this.BindData(ResultView);
        }
    }
    #endregion

    #region DropDownList_SortOrder_SelectedIndexChanged
    protected void DropDownList_SortOrder_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (this.ResultTable != null)
        {
            DataView ResultView = new DataView(this.ResultTable);
            ResultView.Sort = this.DropDownList_SortBy.SelectedValue + " " + this.DropDownList_SortOrder.SelectedValue;
            this.BindData(ResultView);
        }
    }
    #endregion

    #region Button_Submit_Click
    protected void Button_Submit_Click(object sender, EventArgs e)
    {
        if (this.DataValidate())
        {
            using (UserManager CurUserManager = new UserManager(this.CurrentPrivateSession))
            {
                if (CurUserManager.AddNewFinanceAdmin(
                    this.DropDownList_ByCompany.SelectedValue,
                    this.HiddenField_PersonnelInternalID.Value,this.CheckBox_IsFinancialManager.Checked))
                {
                    // log down the history
                    if (CheckBox_IsFinancialManager.Checked)
                    {
                        this.CurLogManager.LogMessage("[GonzalesAdminFAListing] : New Finance Manager (" + this.HiddenField_PersonnelInternalID.Value + ") added for Company(" + this.DropDownList_ByCompany.SelectedValue + ", " + this.DropDownList_ByCompany.SelectedItem.Text + ")", this.CurrentPrivateSession.CurrentLoggedOnUser, LogInterface.User);
                    }
                    else
                    {
                        this.CurLogManager.LogMessage("[GonzalesAdminFAListing] : New Finance Admin (" + this.HiddenField_PersonnelInternalID.Value + ") added for Company(" + this.DropDownList_ByCompany.SelectedValue + ", " + this.DropDownList_ByCompany.SelectedItem.Text + ")", this.CurrentPrivateSession.CurrentLoggedOnUser, LogInterface.User);
                    }

                    SystemUser ResultFA = CurUserManager.GetFinanceAdminByID(this.HiddenField_PersonnelInternalID.Value, this.DropDownList_ByCompany.SelectedValue);
                    // Added by thangnv on 20130703 -- Log Change
                    if (ResultFA != null)
                    {
                        #region Logged By Role
                        string LoggedByRole = string.Empty;
                        if (this.CurrentPrivateSession.CurrentLoggedOnUser.IsFinanceAdmin)
                        {
                            if (this.CurrentPrivateSession.CurrentLoggedOnUser.IsFinancialManager)
                            {
                                LoggedByRole = GonzalesUserRole.FinanceManager;
                            }
                            else
                            {
                                LoggedByRole = GonzalesUserRole.FinanceAdmin;
                            }
                        }
                        else if (this.CurrentPrivateSession.CurrentLoggedOnUser.IsPowerAdmin)
                        {
                            LoggedByRole = GonzalesUserRole.PowerAdmin;
                        }
                        else if (this.CurrentPrivateSession.CurrentLoggedOnUser.IsITAdmin)
                        {
                            LoggedByRole = GonzalesUserRole.ITAdmin;
                        }
                        #endregion

                        this.CurLogManager.ChangeLogFinanceAdmin(this.CurrentPrivateSession.CurrentLoggedOnUser.InternalID, 
                            this.CurrentPrivateSession.CurrentLoggedOnUser.DisplayName, 
                            ResultFA.EmployeeID, ResultFA.DisplayName,
                            ResultFA.FromCompany.InternalID, 
                            ResultFA.FromCompany.CompanyCode, 
                            ResultFA.FromCompany.CompanyName, 
                            GonzalesUserAction.Added, 
                            ResultFA.FromCompany.Entity.InternalID, 
                            ResultFA.InternalID,
                            (ResultFA.IsFinancialManager ? 1 : 0), LoggedByRole, ResultFA.EmailID,
                            this.DropDownList_ByCompany.SelectedValue);
                    }

                    this.ShowMessage(this.SavedSucessfulMessage);
                }
                else
                {
                    this.ShowErrorMessage(this.SavedFailedMessagee);
                    this.CurLogManager.LogError("[GonzalesAdminFAListing.Button_Submit_Click] : CurUserManager.AddNewFinanceAdmin : " + CurUserManager.ErrorMessage, this.CurrentPrivateSession.CurrentLoggedOnUser, LogInterface.System);
                }

                this.LoadData();
                if (this.ResultTable != null)
                {
                    DataView ResultView = new DataView(this.ResultTable);
                    ResultView.Sort = this.DropDownList_SortBy.SelectedValue + " " + this.DropDownList_SortOrder.SelectedValue;
                    this.BindData(ResultView);
                }
            }
        }
    }
    #endregion

    #region OnRowCreated
    protected void OnRowCreated(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.Header)
        {
            TableCellCollection cells = e.Row.Cells;

            for (int i = 0; i < this.GridViewHeader.Count; i++)
            {
                cells[i].Text = this.GridViewHeader[i].ToString();
            }
        }
    }
    #endregion

    #endregion

    #region Customized Methods

    #region SessionCheck
    public void SessionCheck()
    {

        if (Session[GonzalesCommonNamingConvention.CurrentPrivateSession] != null)
        {
            this.CurrentPrivateSession = (PrivateLoginSession)Session[GonzalesCommonNamingConvention.CurrentPrivateSession];
            this.CurLogManager = new LogManager(this.CurrentPrivateSession);    // activate Log Manager
        }
        else
        {
            Response.Redirect(GonzalesErrorPageRedirect.SessionError);
        }

    }
    #endregion

    #region PageComponentSetup
    protected void PageComponentSetup()
    {
        // setup entity
        if (this.CurrentPrivateSession.CurrentLoggedOnUser.IsPowerAdmin || this.CurrentPrivateSession.CurrentLoggedOnUser.IsITAdmin)
        {
            #region Power Admin
            using (EntityManager CurEntityManager = new EntityManager(this.CurrentPrivateSession))
            {
                MasterBaseCollection ResultList = CurEntityManager.GetAllEntity();
                if (ResultList != null)
                {
                    this.DropDownList_ByEntity.Items.Add(new ListItem("", ""));
                    for (int x = 0; x < ResultList.Count; x++)
                    {
                        this.DropDownList_ByEntity.Items.Add(new ListItem(ResultList[x].DisplayName, ResultList[x].InternalID));
                    }
                }
                else
                {
                    // display error
                    this.CurLogManager.LogError("[GonzalesAdminClaimantsListing.PageComponentSetup] : Failed on CurEntityManager.GetAllEntity() : " + CurEntityManager.ErrorMessage, this.CurrentPrivateSession.CurrentLoggedOnUser, LogInterface.System);

                }
            }
            #endregion
        }
        else
        {
            #region Finance Admin

            using (UserManager CurManager = new UserManager(this.CurrentPrivateSession))
            {
                MasterBaseCollection ResultList = CurManager.GetEntityByFinanceAdmin(this.CurrentPrivateSession.CurrentLoggedOnUser.InternalID);
                if (ResultList != null)
                {
                    for (int x = 0; x < ResultList.Count; x++)
                    {
                        this.DropDownList_ByEntity.Items.Add(new ListItem(ResultList[x].DisplayName, ResultList[x].InternalID));
                    }
                }
                else
                {
                    // display error
                    this.CurLogManager.LogError("[GonzalesAdminClaimantsListing.PageComponentSetup] : Failed on CurEntityManager.GetAllEntity() : " + CurManager.ErrorMessage, this.CurrentPrivateSession.CurrentLoggedOnUser, LogInterface.System);
                }
            }
            this.DropDownList_ByEntity_SelectedIndexChanged(null, null);
            #endregion
        }

        // browse button
        this.Button_Browse.Attributes["onclick"] = "ShowModal('AddressBook', document.getElementById('ModalResult')); return false;";

    }
    #endregion

    #region SwitchLanguage
    protected void SwitchLanguage()
    {
        try
        {
            using (MultiLingualFactory CurLanguageFactory = MultiLingualEngine.GetMultiLingualFactory(this, this.CurrentPrivateSession.CurrentLoggedOnUser.PreferedLanguage.InternalID))
            {
                this.Label_AddNew.Text = CurLanguageFactory.DisplayValue("AddNew");
                this.Label_Company.Text = CurLanguageFactory.DisplayValue("Company");
                this.Label_Information.Text = CurLanguageFactory.DisplayValue("Information");
                this.Label_PageTitle.Text = CurLanguageFactory.DisplayValue("PageTitle");
                this.Label_Personnel.Text = CurLanguageFactory.DisplayValue("Personnel");
                this.Button_Browse.Text = CurLanguageFactory.DisplayValue("Browse");
                this.Button_Submit.Text = CurLanguageFactory.DisplayValue("Submit");

                this.GridViewHeader = new ArrayList();
                this.GridViewHeader.Add(CurLanguageFactory.DisplayValue("EmployeeID"));
                this.GridViewHeader.Add(CurLanguageFactory.DisplayValue("ADName"));
                this.GridViewHeader.Add(CurLanguageFactory.DisplayValue("DisplayName"));

                this.SavedSucessfulMessage = CurLanguageFactory.DisplayValue("SavedSucessfulMessage");
                this.SavedFailedMessagee = CurLanguageFactory.DisplayValue("SavedFailedMessagee");
                this.LoadFailedMessage = CurLanguageFactory.DisplayValue("LoadFailedMessage");
                this.CompanyMessage = CurLanguageFactory.DisplayValue("CompanyMessage");
                this.FinanceAdminMessage = CurLanguageFactory.DisplayValue("FinanceAdminMessage");
                this.DuplicateFAMessage = CurLanguageFactory.DisplayValue("DuplicateFAMessage");
                this.DeletionFailedMessage = CurLanguageFactory.DisplayValue("DeletionFailedMessage");
                
                this.DropDownList_SortBy.Items.Add(new ListItem(CurLanguageFactory.DisplayValue("EmployeeID"), this.CurPageDataObj.EmployeeID));
                this.DropDownList_SortBy.Items.Add(new ListItem(CurLanguageFactory.DisplayValue("DisplayName"), this.CurPageDataObj.DisplayName));
                

                this.DropDownList_SortOrder.Items.Add(new ListItem(CurLanguageFactory.DisplayValue("ASC"), "ASC"));
                this.DropDownList_SortOrder.Items.Add(new ListItem(CurLanguageFactory.DisplayValue("DESC"), "DESC"));
            }
        }
        catch (Exception ex)
        {
            this.CurLogManager.LogError("[GonzalesMyClaims.SwitchLanguage.EX] : " + ex.Message, this.CurrentPrivateSession.CurrentLoggedOnUser, LogInterface.User);
        }

    }
    #endregion

    #region ShowErrorMessage
    protected void ShowErrorMessage(string ErrorMessage)
    {
        this.Table_MessageBox.Visible = true;
        this.Table_MessageBox.Rows[0].Cells[0].Text = ErrorMessage;
        this.Table_MessageBox.Rows[0].Cells[0].CssClass = "ErrorBox";
    }
    #endregion

    #region ShowMessage
    protected void ShowMessage(string Message)
    {
        this.Table_MessageBox.Visible = true;
        this.Table_MessageBox.Rows[0].Cells[0].Text = Message;
        this.Table_MessageBox.Rows[0].Cells[0].CssClass = "MessageBox";
    }
    #endregion

    #endregion

    #region Data Operation

    #region LoadData
    protected void LoadData()
    {
        // only when is selected from the drop down
        if (this.DropDownList_ByCompany.SelectedIndex > 0)
        {
            using (UserManager CurUserManager = new UserManager(this.CurrentPrivateSession))
            {
                SystemUsers ResultObj = CurUserManager.GetFinanceAdminByCompany(this.DropDownList_ByCompany.SelectedValue);

                if (ResultObj != null)
                {
                    this.ResultTable = new DataTable();
                    ResultTable.Columns.Add(new DataColumn(this.CurPageDataObj.InternalID, Type.GetType("System.String")));
                    ResultTable.Columns.Add(new DataColumn(this.CurPageDataObj.EmployeeID, Type.GetType("System.String")));
                    ResultTable.Columns.Add(new DataColumn(this.CurPageDataObj.ADName, Type.GetType("System.String")));
                    ResultTable.Columns.Add(new DataColumn(this.CurPageDataObj.Role, Type.GetType("System.String")));
                    ResultTable.Columns.Add(new DataColumn(this.CurPageDataObj.IsFinancialManager, Type.GetType("System.String")));
                    ResultTable.Columns.Add(new DataColumn(this.CurPageDataObj.DisplayName, Type.GetType("System.String")));
                    ResultTable.Columns.Add(new DataColumn(this.CurPageDataObj.DeleteLink, Type.GetType("System.String")));


                    for (int x = 0; x < ResultObj.Count; x++)
                    {
                        DataRow RowObj = ResultTable.NewRow();

                        RowObj[this.CurPageDataObj.InternalID] = ResultObj[x].InternalID;
                        RowObj[this.CurPageDataObj.EmployeeID] = ResultObj[x].EmployeeID;
                        RowObj[this.CurPageDataObj.ADName] = ResultObj[x].EmailID;
                        RowObj[this.CurPageDataObj.DisplayName] = ResultObj[x].DisplayName;
                        RowObj[this.CurPageDataObj.IsFinancialManager] = (ResultObj[x].IsFinancialManager) ;//? "<img src='" + GonzalesImages.Icon_Checked + "'>" : "";
                        RowObj[this.CurPageDataObj.Role] = (ResultObj[x].IsFinancialManager ? "Finance Manager" : "Finance Admin");

                        if (this.CurrentPrivateSession.CurrentLoggedOnUser.IsFinanceAdmin)
                        {
                            if (this.CurrentPrivateSession.CurrentLoggedOnUser.IsFinancialManager)
                            {
                                if(!(ResultObj[x].IsFinancialManager))
                                    RowObj[this.CurPageDataObj.DeleteLink] = "<a class='GridViewLink' href='GonzalesAdminFAListing.aspx?DELETE=TRUE&eid=" + this.DropDownList_ByEntity.SelectedValue + "&id=" + this.DropDownList_ByCompany.SelectedValue + "&did=" + ResultObj[x].InternalID + "' onclick=\"return confirm('Are you sure?');\">Delete</a>";
                            }
                        }
                        else if (this.CurrentPrivateSession.CurrentLoggedOnUser.IsITAdmin)
                        {
                            this.GridViewResult.Columns[this.GridViewResult.Columns.Count - 1].Visible = false;
                            this.GridViewResult.Columns[this.GridViewResult.Columns.Count - 2].Visible = false;
                        }
                        else
                        {
                            if (ResultObj[x].IsFinancialManager)
                                RowObj[this.CurPageDataObj.DeleteLink] = "<a class='GridViewLink' href='GonzalesAdminFAListing.aspx?DELETE=TRUE&eid=" + this.DropDownList_ByEntity.SelectedValue + "&id=" + this.DropDownList_ByCompany.SelectedValue + "&did=" + ResultObj[x].InternalID + "' onclick=\"return confirm('Are you sure?');\">Delete</a>";
                        }
                        ResultTable.Rows.Add(RowObj);
                    }
                }
                else
                {
                    this.ShowErrorMessage(this.LoadFailedMessage);
                    this.CurLogManager.LogError("[GonzalesAdminFAListing.LoadData] : Failed at CurUserManager.GetUsersByCompany() : " + CurUserManager.ErrorMessage, this.CurrentPrivateSession.CurrentLoggedOnUser, LogInterface.System);
                }

            }
        }
    }

    #endregion

    #region DataValidate
    protected bool DataValidate()
    {
        bool valid = true;
        StringBuilder ErrorMessages = new StringBuilder("<ul>");

        if (this.DropDownList_ByCompany.SelectedValue.Length == 0)
        {
            ErrorMessages.AppendLine("<li>" + this.CompanyMessage + "</li>");
            valid = false;
        }

        if (this.HiddenField_PersonnelInternalID.Value.Length == 0)
        {
            ErrorMessages.AppendLine("<li>" + this.FinanceAdminMessage + "</li>");
            valid = false;
        }

        // check for duplicate entry
        if (this.ResultTable != null)
        {
            foreach (DataRow ResultRow in this.ResultTable.Rows)
            {
                if (ResultRow[this.CurPageDataObj.InternalID].ToString().CompareTo(this.HiddenField_PersonnelInternalID.Value) == 0)
                {
                    ErrorMessages.AppendLine("<li>" + this.DuplicateFAMessage + "</li>");
                    valid = false;
                    break;
                }                                            
            }
        }

        ErrorMessages.AppendLine("<ul>");

        if (!valid) this.ShowErrorMessage(ErrorMessages.ToString());

        return valid;
    }
    #endregion

    #region DataDelete
    protected void DataDelete()
    {
        bool smooth = true;

        if (Request.QueryString["DELETE"] != null && Request.QueryString["DELETE"].CompareTo("TRUE") == 0 &&
            Request.QueryString["id"] != null && Request.QueryString["id"].Length == 36 &&
            Request.QueryString["eid"] != null &&
            Request.QueryString["did"] != null && Request.QueryString["did"].Length == 36)
        {
            SystemUser ResultFA = null;
            using (UserManager CurUserManager = new UserManager(this.CurrentPrivateSession))
            {
                ResultFA = CurUserManager.GetFinanceAdminByID(Request.QueryString["did"], Request.QueryString["id"]);

                smooth = CurUserManager.DeleteFinanceAdmin(Request.QueryString["id"], Request.QueryString["did"]);
                if (!smooth)
                {
                    this.CurLogManager.LogError("[GonzalesAdminFAListing.DataDelete] : Failed at CurUserManager.DeleteFinanceAdmin('" + this.DropDownList_ByCompany.SelectedValue + "', Request.QueryString['" + Request.QueryString["did"] + "']) : " + CurUserManager.ErrorMessage, this.CurrentPrivateSession.CurrentLoggedOnUser, LogInterface.System);
                    this.ShowErrorMessage(this.DeletionFailedMessage);
                }
            }

            if (smooth)
            {
                this.DropDownList_ByEntity.Items.FindByValue(Request.QueryString["eid"]).Selected = true;
                this.DropDownList_ByEntity_SelectedIndexChanged(this, null);               
                this.DropDownList_ByCompany.Items.FindByValue(Request.QueryString["id"]).Selected = true;
                this.LabelValue_Company.Text = this.DropDownList_ByCompany.SelectedItem.Text;

                // Added by thangnv on 20130703 -- Log Change
                if (ResultFA != null)
                {
                    #region Logged By Role
                    string LoggedByRole = string.Empty;
                    if (this.CurrentPrivateSession.CurrentLoggedOnUser.IsFinanceAdmin)
                    {
                        if (this.CurrentPrivateSession.CurrentLoggedOnUser.IsFinancialManager)
                        {
                            LoggedByRole = GonzalesUserRole.FinanceManager;
                        }
                        else
                        {
                            LoggedByRole = GonzalesUserRole.FinanceAdmin;
                        }
                    }
                    else if (this.CurrentPrivateSession.CurrentLoggedOnUser.IsPowerAdmin)
                    {
                        LoggedByRole = GonzalesUserRole.PowerAdmin;
                    }
                    else if (this.CurrentPrivateSession.CurrentLoggedOnUser.IsITAdmin)
                    {
                        LoggedByRole = GonzalesUserRole.ITAdmin;
                    }
                    #endregion

                    this.CurLogManager.ChangeLogFinanceAdmin(this.CurrentPrivateSession.CurrentLoggedOnUser.InternalID, 
                        this.CurrentPrivateSession.CurrentLoggedOnUser.DisplayName, 
                        ResultFA.EmployeeID, 
                        ResultFA.DisplayName,
                        ResultFA.FromCompany.InternalID, 
                        ResultFA.FromCompany.CompanyCode, 
                        ResultFA.FromCompany.CompanyName, 
                        GonzalesUserAction.Deleted, 
                        ResultFA.FromCompany.Entity.InternalID, 
                        ResultFA.InternalID,
                        (ResultFA.IsFinancialManager ? 1 : 0), LoggedByRole, ResultFA.EmailID,
                        this.DropDownList_ByCompany.SelectedValue);
                }
            }
        }
    }

    #endregion

    #region BindData

    private void BindData(DataView result)
    {
        this.GridViewResult.DataSource = result;
        this.GridViewResult.DataBind();
    }

    private void BindData(DataView result, int pageindex)
    {
        this.GridViewResult.PageIndex = pageindex;
        this.GridViewResult.DataSource = result;
        this.GridViewResult.DataBind();
    }

    #endregion

    #endregion

    #region Class: DataObj

    protected class DataObj
    {
        public readonly string InternalID = "InternalID";
        public readonly string EmployeeID = "EmployeeID";
        public readonly string ADName = "ADName";
        public readonly string DisplayName = "DisplayName";
        public readonly string IsFinancialManager = "IsFinancialManager";
        public readonly string DeleteLink = "DeleteLink";
        public readonly string Role = "Role";
               
    }

    #endregion
}
